package org.poptest.processor.annotation;

import org.poptest.model.FieldNode;
import org.poptest.processor.Processor;
import org.poptest.reflect.ReflectionUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * @author Alan Roche
 *         Date: 13/02/11
 *         Time: 15:44
 */
public abstract class AnnotationProcessor<T extends Annotation> implements Processor {
    private final Class<T> annotationClass;

    protected AnnotationProcessor(Class<T> annotationClass) {
        this.annotationClass = annotationClass;
    }

    public boolean isProcessorFor(final Annotation... annotations) {
        return ReflectionUtils.hasInstance(annotationClass, annotations);
    }

    protected T getAnnotation(final FieldNode fieldNode) {
        return fieldNode.getField().getAnnotation(annotationClass);
    }
}
